function reg(){
    var username = $("#username").val();
    var name = $("#name").val();
    var role = $('select option:selected').val();
    var password = $("#password").val();
    var password2 = $("#password2").val();
    var email = $("#email").val();
    var tel = $("#tel").val();
    var reg_name = /^[\u4e00-\u9fa5]{2,10}$/;
    var reg_email = /^\w{3,}(\.\w+)*@[A-z0-9]+(\.[A-z]{2,5}){1,2}$/;
    var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
    var protocol = window.location.protocol;
    var host = window.location.host;
    if (username == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "用户名不能为空！",
            yes:function (index){
                $('#age').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (role == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "您还没有选择身份！",
            yes:function (index){
                $('#age').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (password == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "密码不能为空！",
            yes:function (index){
                $('#age').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (password2 == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "确认密码不能为空！",
            yes:function (index){
                $('#age').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (tel == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "联系电话不能为空！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }else if (!reg_tel.test(tel)){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "您的联系电话格式有误，请从新输入！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (name == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "姓名不能为空！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }else if (!reg_name.test(name)){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "姓名只能由2-10个中文字符组成！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (email == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "邮箱不能为空！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }else if (!reg_email.test(email)){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "您的邮箱格式有误，请从新输入！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }

    $.ajax({
        type : 'POST',
        url : '/reg',
        data : {username:username,name:name,role:role,password:password,password2:password2,email:email,tel:tel,protocol:protocol,host:host},
        success:function (data) {

            if (data == "OK"){
                layer.open({
                    title: '提示信息',
                    anim: 0,
                    resize:false,//是否可以拉伸  默认true
                    icon: 1,
                    shadeClose: true,
                    skin: 'layui-layer-molv',
                    content: "注册成功,请您耐心等待,审核结果会发送到您填写的邮箱！",
                    yes:function (index){
                        window.location.href = protocol+"//"+host+"/toLogin";
                        layer.close(index);
                    }
                });
            }else {
                layer.open({
                    title: '提示信息',
                    anim: 0,
                    resize:false,//是否可以拉伸  默认true
                    icon: 2,
                    shadeClose: true,
                    skin: 'layui-layer-molv',
                    content: data
                });
            }
        },
        error: function (e) {
            console.log(e)
        }
    });
}